package com.shsxt.crm.controller.marketing;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shsxt.common.util.Result;
import com.shsxt.crm.model.YgSaleChance;
import com.shsxt.crm.service.IMarketingService;
import com.shsxt.framework.constant.VerifyType;
import com.shsxt.framework.context.BaseController;
import com.shsxt.framework.permission.Permission;

/**
 * 营销管理
 * 
 * @author Mr.YongGan.Zhang
 *
 */

@Controller
@RequestMapping("/marketing")
public class MarketingController extends BaseController {

	@Autowired
	private IMarketingService marketingService;

	/**
	 * 营销机会管理 客户开发计划 页面的跳转
	 * 
	 * @return
	 */
	@RequestMapping("/{state}/index.shtml")
	public String index(@PathVariable("state") Integer state) {
		switch (state) {
		case 1:
			return "sale_chance";
		case 2:
			return "cus_dev_plan";
		default:
			return "500";
		}
	}

	/**
	 * 查询 营销机会
	 * 
	 * @return
	 * @param saleChance
	 *            提供 全部查询 创建人 客户名称 创建时间 分配状态 参数查询
	 */
	@PostMapping("/querySaleChancesByParams")
	@ResponseBody
	public Map<String, Object> querySaleChancesByParams(YgSaleChance saleChance) {
		return marketingService.querySaleChancesByParams(saleChance);
	}

	/**
	 * 删除记录
	 * @param ids
	 * @return
	 */
	@PostMapping("/delete")
	@ResponseBody
	public Result delMarketingChance(Integer[] ids) {
		return marketingService.delMarketingChance(ids);
	}
	
	@PostMapping("/insert")
	@ResponseBody
	public Result  insertMarketingChance (YgSaleChance saleChance) {
		return marketingService.insertMarketingChance(saleChance);
	}
	
	/**
	 * 修改 营销机会
	 * @param saleChance
	 * @return
	 */
	@PostMapping("/update")
	@ResponseBody
	public Result  updateMarketingChance (YgSaleChance saleChance) {
		return marketingService.insertMarketingChance(saleChance);
	}
	
	/**
	 * 修改   修改 改营销机会 开发结果
	 * @param devResult
	 * @param sid
	 * @return
	 */
	@PostMapping("/updateSaleChanceDevResult")
	@ResponseBody
	public Result updateSaleChanceDevResult (@RequestParam ("devResult")Integer devResult ,@RequestParam ("sid") Integer sid) {
		return marketingService.updateSaleChanceDevResult(devResult, sid);
	}

}
